import globalVar as G
StartPos = None


def startMove(tool, event):
    global StartPos
    win = G.get_value('mainWindow')
    layerList = win.layerList
    graphicsItem = layerList.currentItem.graphicsItem
    tool.graphicsItem = graphicsItem
    sPos = graphicsItem .mapToScene(event.pos())
    tool.offset = (sPos.x() - graphicsItem.pos().x(), sPos.y() - graphicsItem.pos().y())
    tool.isMoving = True
def move(tool, event):
    if tool.isMoving:
        graphicsItem = tool.graphicsItem
        offset = tool.offset
        sPos = graphicsItem.mapToScene(event.pos()) #场景坐标
        sPos.setX(sPos.x() - offset[0])
        sPos.setY(sPos.y() - offset[1])
        graphicsItem.setPos(sPos)

def endMove(tool, event):
    """

    :param tool: 当前工具
    :param event:
    :return:
    """
    global StartPos
    tool.isMoving = False
